/*
 * @Author: Starfish_DL
 * @Date: 2020-11-21 23:18:34
 * @LastEditors: Starfish_DL
 * @LastEditTime: 2020-11-22 19:40:30
 * @CurrentVersion: 1.0
 * @Description:
 */

#include"LinkQueueBox.h"
#include<iostream>
using namespace std;

Box::Box()
{
    this->x = 0;
    this->y = 0;
}

Box::Box(int a, int b)
{
    this->x = a;
    this->y = b;
}

void Box::DisBox()
{
    cout << "(" << this->x << "," << this->y << ")";
}

Box::~Box()
{
}

BoxLinkNode::BoxLinkNode()
{
    this->data = Box(0, 0);
    this->next = nullptr;
}

BoxLinkNode::BoxLinkNode(Box a)
{
    this->data = a;
    this->next = nullptr;
}

BoxLinkNode::BoxLinkNode(Box a, BoxLinkNode* next)
{
    this->data = a;
    this->next = nullptr;
}

BoxLinkNode::~BoxLinkNode()
{
}

BoxLinkQueue::BoxLinkQueue(Box a)
{
    this->head = new BoxLinkNode();
    BoxLinkNode* p = new BoxLinkNode(a);
    this->head->next = p;
}

BoxLinkQueue::BoxLinkQueue(Box boxArray[], int n)
{
    this->head = new BoxLinkNode();
    BoxLinkNode* p;
    BoxLinkNode* s = this->head;
    for (int i = 0; i < n; i++)
    {
        p = new BoxLinkNode(boxArray[i]);
        s->next = p;
        s = p;
    }
}

BoxLinkQueue::BoxLinkQueue()
{
    this->head = new BoxLinkNode();
}

int BoxLinkQueue::GetLength()
{
    BoxLinkNode* p = this->head;
    int length = 0;
    while (p != nullptr)
    {
        p = p->next;
        length++;
    }
    return length;
}

void BoxLinkQueue::EnQueue(Box a)
{
    BoxLinkNode* p = this->head;
    BoxLinkNode* s = new BoxLinkNode(a);
    while (p->next != nullptr)
    {
        p = p->next;
    }
    p->next = s;
}

Box BoxLinkQueue::OutQueue()
{
    BoxLinkNode* p = this->head->next;
    Box temp = p->data;
    this->head->next = p->next;
    delete p;
    return temp;
}

bool BoxLinkQueue::IsEmpty()
{
    if (this->head->next==nullptr)
    {
        return true;
    }
    else
    {
        return false;
    }
}

BoxLinkQueue::~BoxLinkQueue()
{
    BoxLinkNode* p = this->head;
    BoxLinkNode* pre = this->head->next;
    while (pre != nullptr)
    {
        delete p;
        p = pre;
        pre = pre->next;
    }
    delete p;
}

BoxSQueue::BoxSQueue()
{
    for (int i = 0; i < MAXVER_MATGRAPH * MAXVER_MATGRAPH; i++)
    {
        this->data[i] = Box();
    }
}

Box BoxSQueue::OutSQ()
{
    if (this->head < this->down)
    {
        this->head++;
        return this->data[this->head];
    }
    else
    {
        return Box(0, 0);
    }
}

void BoxSQueue::EnSQ(Box a)
{
    if (this->down < MAXVER_MATGRAPH * MAXVER_MATGRAPH - 1)
    {
        this->down++;
        this->data[this->down] = a;
    }
}

int BoxSQueue::Length()
{
    if (this->IsEmpty())
    {
        return 0;
    }
    else
    {
        return this->down - this->head;
    }
}

bool BoxSQueue::IsEmpty()
{
    if (this->head >= this->down)
    {
        return true;
    }
    else
    {
        return false;
    }
}

BoxSQueue::BoxSQueue(Box a)
{
    for (int i = 0; i < MAXVER_MATGRAPH * MAXVER_MATGRAPH; i++)
    {
        this->data[i] = Box();
    }
    this->down++;
    this->data[down] = a;
}

BoxSQueue::~BoxSQueue()
{
}
